package com.parkingspace.config;

import com.alibaba.druid.pool.DruidDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * ClassName: DataSourceProxyConfig
 * Package: com.parkingspace.config
 *
 * @author: guanzepeng
 * @Date: 2021/5/24 17:07 星期一
 * @Description:
 */
@Configuration
public class DataSourceProxyConfig {
	@Bean
	@ConfigurationProperties(prefix = "spring.datasource")
	public DruidDataSource druidDataSource() {
		return new DruidDataSource();
	}

	// 必须在代理数据源上添加@Primary，保证在自动装配时优先注入代理数据源
	@Primary
	@Bean
	public DataSourceProxy dataSource(DruidDataSource druidDataSource) {
		return new DataSourceProxy(druidDataSource);
	}
}
